$(function () {
    //查询用户消息,并渲染
    $.ajax({
        url: '/user/queryUserMessage',
        dataType: 'json',
        success: function (info) {
            console.log(info);
            if(info.error == 400) {//错误代表没登录
                location.href = 'login.html';
                return;
            }
            $('#userInfo').html(template('tmp-user', info));
        }
    });

    // 点击退出,跳转到login.html
    $('#logout').on('click', function () {
        $.ajax({
            url: '/user/logout',
            dataType: 'json',
            success: function (info) {
                console.log(info);
                if (info.success) {
                    //跳转到login.html
                    location.href = 'login.html';
                }
            }
        });
    });
})